home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_devices / rkrm_devices.lha / Resources / Alloc_Misc.a < prev    next >
Text File  |  1992-09-03  |  4KB  |  114 lines

  1. *
  2. * Copyright (c) 1992 Commodore-Amiga, Inc.
  3. * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  4. * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  5. * published by Addison-Wesley (ISBN 0-201-56775-X).
  6. * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  7. * information on the correct usage of the techniques and operating system 
  8. * functions presented in these examples.  The source and executable code 
  9. * of these examples may only be distributed in free electronic form, via 
  10. * bulletin board or as part of a fully non-commercial and freely 
  11. * redistributable diskette.  Both the source and executable code (including 
  12. * comments) must be included, without modification, in any copy.  This 
  13. * example may not be published in printed form or distributed with any
  14. * commercial product.  However, the programming techniques and support
  15. * routines set forth in these examples may be used in the development
  16. * of original executable software products for Commodore Amiga computers.
  17. * All other rights reserved.
  18. * This example is provided "as-is" and is subject to change; no
  19. * warranties are made.  All use is at your own risk. No liability or
  20. * responsibility is assumed.
  21. *
  22. ******************************************************************************
  23. *
  24. * Alloc_Misc.a
  25. *
  26. * Assembly language fragment that grabs the two parts of the serial
  27. * resource (using misc.resource).  If it gets the resource, it will
  28. * wait for CTRL-C to be pressed before releasing.
  29. *
  30. * While we are waiting, the query_serial program should be run.  It will try
  31. * to open the serial device and if unsuccessful, will return the name of the
  32. * owner.  It will be us, Serial Port Hog!
  33. *
  34. * When a task has successfully obtained the serial resource, it "owns"
  35. * the hardware registers that control the serial port.  No other tasks
  36. * are allowed to interfere.
  37. *
  38. * Assemble with Adapt
  39. *     HX68 Alloc_Misc.a to Alloc_Misc.o
  40. *
  41. * Link
  42. *     Blink FROM Alloc_Misc.o TO Alloc_Misc LIB LIB:amiga.lib
  43. *
  44. *
  45. *               CSECT Alloc_Misc ; SAS/Lattice ASM command needs this
  46. *
  47.                 INCDIR  "include:"
  48.                 INCLUDE "exec/types.i"
  49.                 INCLUDE "resources/misc.i"
  50.                 INCLUDE "dos/dos.i"
  51.  
  52.         xref    _AbsExecBase     ; We get this from outside...
  53.         xref    _LVOOpenResource ; We get this from outside...
  54.         xref    _LVOWait         ; We get this from outside...
  55.  
  56. ;
  57. ; Open Exec and the misc.resource, check for success
  58. ;
  59.                 move.l  _AbsExecBase,a6         ;Prepare to use exec
  60.                 lea.l   MiscName(pc),a1
  61.                 jsr    _LVOOpenResource(a6)    ;Open "misc.resource"
  62.                 move.l  d0,d7                   ;Stash resource base
  63.                 bne.s   resource_ok
  64.                 moveq   #RETURN_FAIL,d0
  65.                 rts
  66.  
  67. resource_ok     exg.l   d7,a6                   ;Put resource base in A6
  68.  
  69. ;
  70. ; We now have a pointer to a resource.
  71. ; Call one of the resource's library-like vectors.
  72. ;
  73.                 move.l  #MR_SERIALBITS,d0       ;We want these bits
  74.                 lea.l   MyName(pc),a1           ;This is our name
  75.                 jsr     MR_ALLOCMISCRESOURCE(a6)
  76.                 tst.l   d0
  77.                 bne.s   no_bits                 ;Someone else has it...
  78.                 move.l  #MR_SERIALPORT,d0
  79.                 lea.l   MyName(pc),a1
  80.                 jsr     MR_ALLOCMISCRESOURCE(a6)
  81.                 tst.l   d0
  82.                 bne.s   no_port                 ;Someone else has it...
  83.  
  84. ;
  85. ; We just stole the serial port registers; wait.
  86. ; Nobody else can use the serial port, including the serial.device!
  87. ;
  88.                 exg.l   d7,a6                   ;use exec again
  89.                 move.l  #SIGBREAKF_CTRL_C,d0
  90.                 jsr    _LVOWait(a6)            ;Wait for CTRL-C
  91.                 exg.l   d7,a6                   ;Get resource base back
  92. ;
  93. ; Free 'em up
  94. ;
  95.                 move.l  #MR_SERIALPORT,d0
  96.                 jsr     MR_FREEMISCRESOURCE(a6)
  97. no_port
  98.                 move.l  #MR_SERIALBITS,d0
  99.                 jsr     MR_FREEMISCRESOURCE(a6)
  100. no_bits
  101.                 moveq   #RETURN_FAIL,d0
  102.                 rts
  103. ;
  104. ; Text area
  105. ;
  106. MiscName        dc.b    'misc.resource',0
  107. MyName          dc.b    'Serial Port Hog',0
  108.                 dc.w    0
  109.                 END
  110.